<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>预定义常量</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="password.resources.html">« 资源类型</a></li>
      <li style="float: right;"><a href="ref.password.html">密码散列算法函数 »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.password.html">密码散列算法</a></li>
    <li>预定义常量</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="password.constants" class="appendix">
 <h1>预定义常量</h1>

 <p class="simpara">
下列常量作为 PHP 核心的一部分总是可用的。
</p>

 <p class="para">
  <dl>
   
    <dt id="constant.password-bcrypt">
     <strong><code>PASSWORD_BCRYPT</code></strong>
     (<span class="type">string</span>)
    </dt>

    <dd>

     <p class="para">
      <strong><code>PASSWORD_BCRYPT</code></strong> is used to create new password
      hashes using the <strong><code>CRYPT_BLOWFISH</code></strong> algorithm.
     </p>
     <p class="para">
      This will always result in a hash using the &quot;$2y$&quot; crypt format, 
      which is always 60 characters wide.
     </p>
     <p class="para">
      Supported Options:
     </p>
     <ul class="itemizedlist">
      <li class="listitem">
       <p class="para">
        <code class="literal">salt</code> (<span class="type">string</span>) - to manually provide a salt to use when hashing the password.
        Note that this will override and prevent a salt from being automatically generated.
       </p>
       <p class="para">
        If omitted, a random salt will be generated by <span class="function"><a href="function.password-hash.html" class="function">password_hash()</a></span> for
        each password hashed. This is the intended mode of operation
        and as of PHP 7.0.0 the salt option has been deprecated.
       </p>
      </li>
      <li class="listitem">
       <p class="para">
        <code class="literal">cost</code> (<span class="type">int</span>) - which denotes the algorithmic cost that 
        should be used. Examples of these values can be found on the <span class="function"><a href="function.crypt.html" class="function">crypt()</a></span> 
        page.
       </p>
       <p class="para">
        If omitted, a default value of <code class="literal">10</code> will be used. This is a good
        baseline cost, but you may want to consider increasing it depending on your hardware.
       </p>
      </li>
     </ul>
    </dd>

   
   
    <dt id="constant.password-argon2i">
     <strong><code>PASSWORD_ARGON2I</code></strong>
     (<span class="type">string</span>)
    </dt>

    <dd>

     <p class="para">
      <strong><code>PASSWORD_ARGON2I</code></strong> is used to create new password
      hashes using the Argon2i algorithm.
     </p>
     <p class="para">
      Supported Options:
     </p>
     <ul class="itemizedlist">
      <li class="listitem">
       <p class="para">
        <code class="literal">memory_cost</code> (<span class="type">int</span>) - Maximum memory (in kibibytes) that may 
        be used to compute the Argon2 hash. Defaults to <strong><code>PASSWORD_ARGON2_DEFAULT_MEMORY_COST</code></strong>.
       </p>
      </li>
      <li class="listitem">
       <p class="para">
        <code class="literal">time_cost</code> (<span class="type">int</span>) - Maximum amount of time it may 
        take to compute the Argon2 hash. Defaults to <strong><code>PASSWORD_ARGON2_DEFAULT_TIME_COST</code></strong>.
       </p>
      </li>
      <li class="listitem">
       <p class="para">
        <code class="literal">threads</code> (<span class="type">int</span>) - Number of threads to use for computing 
        the Argon2 hash. Defaults to <strong><code>PASSWORD_ARGON2_DEFAULT_THREADS</code></strong>.
        Only available with libargon2, not with libsodium implementation.
       </p>
      </li>
     </ul>
     <p class="para">
      Available as of PHP 7.2.0.
     </p>
    </dd>

    
   
    <dt id="constant.password-argon2id">
     <strong><code>PASSWORD_ARGON2ID</code></strong>
     (<span class="type">string</span>)
    </dt>

    <dd>

     <p class="para">
      <strong><code>PASSWORD_ARGON2ID</code></strong> is used to create new password
      hashes using the Argon2id algorithm. It supports the same options as
      <a href="password.constants.html#constant.password-argon2i" class="link"><strong><code>PASSWORD_ARGON2I</code></strong></a>.
     </p>
     <p class="para">
      Available as of PHP 7.3.0.
     </p>
    </dd>

   
   
    <dt id="constant.password-argon2-default-memory-cost">
     <strong><code>PASSWORD_ARGON2_DEFAULT_MEMORY_COST</code></strong>
     (<span class="type">int</span>)
    </dt>

    <dd>

     <p class="para">
      Default amount of memory in bytes that will be used while trying to
      compute a hash.
     </p>
     <p class="para">
      Available as of PHP 7.2.0.
     </p>
    </dd>

   
   
    <dt id="constant.password-argon2-default-time-cost">
     <strong><code>PASSWORD_ARGON2_DEFAULT_TIME_COST</code></strong>
     (<span class="type">int</span>)
    </dt>

    <dd>

     <p class="para">
      Default amount of time that will be spent trying to compute a hash.
     </p>
     <p class="para">
      Available as of PHP 7.2.0.
     </p>
    </dd>

   
   
    <dt id="constant.password-argon2-default-threads">
     <strong><code>PASSWORD_ARGON2_DEFAULT_THREADS</code></strong>
     (<span class="type">int</span>)
    </dt>

    <dd>

     <p class="para">
      Default number of threads that Argon2lib will use.
      Not available with libsodium implementation.
     </p>
     <p class="para">
      Available as of PHP 7.2.0.
     </p>
    </dd>

   
   
    <dt id="constant.password-default">
     <strong><code>PASSWORD_DEFAULT</code></strong>
     (<span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span>)
    </dt>

    <dd>

     <p class="para">
      The default algorithm to use for hashing if no algorithm is provided.
      This may change in newer PHP releases when newer, stronger hashing
      algorithms are supported.
     </p>
     <p class="para">
      It is worth noting that over time this constant can (and likely will)
      change. Therefore you should be aware that the length of the resulting
      hash can change. Therefore, if you use <strong><code>PASSWORD_DEFAULT</code></strong>
      you should store the resulting hash in a way that can store more than 60
      characters (255 is the recommended width).
     </p>
     <p class="para">
      Values for this constant:
     </p>
     <ul class="itemizedlist">
      <li class="listitem">
       <span class="simpara">
        PHP 5.5.0 - <strong><code>PASSWORD_BCRYPT</code></strong>
       </span>
      </li>
     </ul>
    </dd>

   
  </dl>

 </p>

 <p class="formalpara">
  <h5 class="title">更新日志</h5>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>7.4.0</td>
       <td>
        The values of the password algo IDs (<strong><code>PASSWORD_BCRYPT</code></strong>, <strong><code>PASSWORD_ARGON2I</code></strong>,
        <strong><code>PASSWORD_ARGON2ID</code></strong> and <strong><code>PASSWORD_DEFAULT</code></strong>) are now <span class="type">string</span>s.
        Previously, they have been <span class="type">int</span>s.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </p>

</div>
</div></div></body></html>